﻿using UnityEngine;
using System.Collections;

public class WinCondition : MonoBehaviour {

	public ShipManager shipManager;
	public ParticleSystem[] winParticles;
	public GameObject[] winDoor;
	public float counter=0;
	public bool open = false;
	public Vector3 cloeDoor=new Vector3(0,0,0);
	public Vector3 openDoor=new Vector3(0,0,0);
	public float DoorSpeed=2F;
	void Update () 
	{
	
			if (open.Equals (true)) {
				for(int i=0;i<winDoor.Length;i++){
					winDoor[i].transform.localPosition = openDoor;
				}
			} else {
				for(int i=0;i<winDoor.Length;i++){
					winDoor[i].transform.localPosition = Vector3.Lerp (winDoor[i].transform.localPosition,cloeDoor,Time.deltaTime*DoorSpeed);		
				}
			}
			if (ShipManager.instance.currentShip != null) {
				open=true;
				if (ShipManager.instance.currentShip.landingTrigger.target != null) {
					Debug.Log ("YOUWIN");
					for (int i=0; i<winParticles.Length; i++) {
						winParticles [i].enableEmission = true;
					}
				}
				else{
					open=false;
					for (int i=0; i<winParticles.Length; i++) {
						winParticles [i].enableEmission = false;
					}
				}
			}
		}
	}